import datetime

# 时间格式
now = datetime.datetime.now()
# 转成字符串
c_time = now.strftime('%Y%m%d_%H%M%S')
print(c_time)

log_time = c_time+'.log'
with open(log_time, 'w+', encoding='utf-8') as f:
    # 时间 [level] line: 13 this is a log message
    message = f"{now} [info] line: 14 this is a log message"
    f.write(message)